<template>
	<div class="box">
		<HomeProductItem :cateList="cateList"  page="firstPage"></HomeProductItem>
	</div>
</template>

<script>
	import HomeProductItem from "../../../real-components/HomeProductItem";
	import { mapGetters,mapMutations } from "vuex";
	import { getPageTree, initDomTree } from "../../../utils/getPageTree";
	import axios from "axios";
	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				msg: '这是首页',
				page: "home",
				componentName: "HomeProductItem",
				cateListcodedata:[],
				cateListcode:"",
				cateList: [],
				// erp所有分类
				/*erpCateList: [],*/
			}
		},
		computed: {
			...mapGetters([
				"getDomTree"
			]),
			pageTree() {
				return getPageTree(this, this.page);
			}
		},
		components: {
			HomeProductItem,
		},
		methods: {
			...mapMutations('xxy', [
				"setseeall",
			]),
			// 请求分类配置数据
		    /*queryCate() {
				return axios.post(api.local_host +'/resourceLevel/resourceLevelListH5', {
					enterpriseId: api.enterpriseId,
					relPosition: 'MallNavigation',
				})
			},*/

			// 请求erp分类接口
			/*queryErpCate() {
				return axios.get(api.mall_goods_host+'/goodsclass/getgoodsclasslist?enterpriseid=' + api.enterpriseId)
			},*/

			// 根据ERP分类数据和后台分类配置数据渲染分类模块
			renderCate() {
				/*axios.all([this.queryCate(), this.queryErpCate()]).then((axios.spread((res, erpRes) => {
					let cateConfig = res.data.data[0]
					let cateList = erpRes.data.data[0]
					this.erpCateList = cateList
					cateConfig && cateConfig.map((item, index) => {
						if(item.promotionType == 3) {
							cateList && cateList.map((val) => {
								if(val.goodsclasscode == item.title) {
									item.classificationId = val.goodsclasscode
									item.title = val.goodsclassname
									item.image = val.imgurl
									return
								}
							})
						}
					})
					this.cateList = cateConfig
				})))*/
				for(var i=0;i<this.list.length;i++){
					this.cateListcodedata.push(this.list[i].goodsCode)
				}
				this.cateListcode=this.cateListcodedata.join(",")

				let url = window.api.goods_host + "/goodsClass/mobile/list";
				let options = {
					method: "get",
					url,
					params: {
						enterpriseCode: api.enterpriseCode,
						codes: this.cateListcode
					},
				}
				axios(options).then(data => {
					this.cateList = data.data.data
				/*console.log(this.cateList,"shuju123")*/
				})
			},
		},
		watch:{
			list(){
				this.renderCate()
			}
		},
		created() {
			this.renderCate()
			this.setseeall(true)
		},
		mounted() {
			// initDomTree(this.getDomTree[this.page]);

		},
		updated() {
			//页面更新完毕
			// initDomTree(this.getDomTree[this.page]);
		}
	}
</script>

<style>

</style>
